package com.cn.kehong.controller;

import com.cn.kehong.api.IProductChuciPeriodService;
import com.cn.kehong.api.IProductGzPeriodService;
import com.cn.kehong.domain.ProductChuciPeriod;
import com.cn.kehong.domain.ProductGzPeriod;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/gz")
public class ProductGzPeriodController {

    @Autowired
    private IProductGzPeriodService productGzPeriodService;


    @RequestMapping("/getProductGzPeriodList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductGzPeriod>> getProductGzPeriodList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ProductGzPeriod> > response = new JsonResponse<List<ProductGzPeriod> >();
        List<ProductGzPeriod> lists = productGzPeriodService.getProductGzPeriodList(queryForm);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/updateChooseGzGuan/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateChooseGzGuan(ProductGzPeriod productGzPeriod, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productGzPeriodService.updateChooseGzGuan(productGzPeriod);
        return CommonUtil.getResponseData(response,result);
    }


    @RequestMapping("/updateEndGzPeriod/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateEndGzPeriod(ProductGzPeriod productGzPeriod, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productGzPeriodService.updateEndGzPeriod(productGzPeriod);
        return CommonUtil.getResponseData(response,result);
    }


    @RequestMapping("/getChengpinList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductGzPeriod>> getChengpinList(String factoryName, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ProductGzPeriod> > response = new JsonResponse<List<ProductGzPeriod> >();
        List<ProductGzPeriod> lists = productGzPeriodService.getChengpinList(factoryName);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

}
